﻿//EntityRegistry.cs
//Copyright (c) 2013 StockSharp LLC, all rights reserved.
//This code module is part of StockSharp library.
//This code is licensed under the GNU GENERAL PUBLIC LICENSE Version 3.
//See the file License.txt for the license details.
//More info on: http://stocksharp.com

namespace StockSharp.Algo.Storages
{
	using System;

	using Ecng.Configuration;
	using Ecng.Serialization;

	using StockSharp.BusinessEntities;

	/// <summary>
	/// Хранилище торговых сущностей.
	/// </summary>
	public class EntityRegistry : IEntityRegistry
	{
		/// <summary>
		/// Создать <see cref="EntityRegistry"/>.
		/// </summary>
		public EntityRegistry()
			: this(new InMemoryStorage())
		{
		}

		/// <summary>
		/// Создать <see cref="EntityRegistry"/>.
		/// </summary>
		/// <param name="storage">Специальный интерфейс для прямого доступа к хранилищу.</param>
		public EntityRegistry(IStorage storage)
		{
			if (storage == null)
				throw new ArgumentNullException("storage");

			Storage = storage;

			if (!ConfigManager.IsServiceRegistered<IStorage>())
				ConfigManager.RegisterService(storage);

			Exchanges = new ExchangeList(storage) { BulkLoad = true };
			ExchangeBoards = new ExchangeBoardList(storage);
			Securities = new SecurityList(storage);
			Trades = new TradeList(storage);
			MyTrades = new MyTradeList(storage);
			Orders = new OrderList(storage);
			OrderFails = new OrderFailList(storage);
			Portfolios = new PortfolioList(storage);
			Positions = new PositionList(storage);
		}

		/// <summary>
		/// Специальный интерфейс для прямого доступа к хранилищу.
		/// </summary>
		public IStorage Storage { get; private set; }

		/// <summary>
		/// Список бирж.
		/// </summary>
		public virtual IStorageEntityList<Exchange> Exchanges { get; private set; }

		/// <summary>
		/// Список биржевых площадок.
		/// </summary>
		public virtual IStorageEntityList<ExchangeBoard> ExchangeBoards { get; private set; }

		/// <summary>
		/// Список инструментов.
		/// </summary>
		public virtual IStorageEntityList<Security> Securities { get; private set; }

		/// <summary>
		/// Список портфелей.
		/// </summary>
		public virtual IStorageEntityList<Portfolio> Portfolios { get; private set; }

		/// <summary>
		/// Список позиций.
		/// </summary>
		public virtual IStorageEntityList<Position> Positions { get; private set; }

		/// <summary>
		/// Список собственных сделок.
		/// </summary>
		public virtual IStorageEntityList<MyTrade> MyTrades { get; private set; }

		/// <summary>
		/// Список тиковых сделок.
		/// </summary>
		public virtual IStorageEntityList<Trade> Trades { get; private set; }

		/// <summary>
		/// Список заявок.
		/// </summary>
		public virtual IStorageEntityList<Order> Orders { get; private set; }

		/// <summary>
		/// Список ошибок регистрации и снятия заявок.
		/// </summary>
		public virtual IStorageEntityList<OrderFail> OrderFails { get; private set; }
	}
}